package com.shh.rabbitmq.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.shh.rabbitmq.common.CommonMapperResultList;
import com.shh.rabbitmq.domin.OrderDO;
import com.shh.rabbitmq.domin.OrderMsgDO;
import com.shh.rabbitmq.mapper.OrderMapper;

@Repository
public class OrderMsgDao {
	
	  @Autowired
	  private JdbcTemplate jdbcTemplate;
	  
	  private String addSql = "insert into ORDER_MESSAGE(orderno,orderstate) values ('%s','%s')";
	  private String upSql = "update ORDER_MESSAGE set orderstate='%s' where orderno=%s";
	  private String querySql = "SELECT o.ORDERNO,o.ORDERDESC FROM ORDER_MESSAGE AS msg   LEFT JOIN  order_data AS o ON o.orderno = msg.orderno  WHERE msg.ORDERSTATE = 0";
	  
	  public void addOrder(OrderMsgDO msg) {
	    String sql = String.format(addSql, msg.getOrderNo(), msg.getOrderState());
	    jdbcTemplate.execute(sql);
	  }
	  
	  public void updateModel(OrderMsgDO msg) {
	    String sql = String.format(upSql, msg.getOrderState(), msg.getOrderNo());
	    jdbcTemplate.execute(sql);
	  }
	  
	  public List<OrderDO> getUnSendOrder() {
		  return jdbcTemplate.query(querySql, new CommonMapperResultList<OrderDO>(OrderDO.class));
      }

}
